package 集合.List集合;

public class 数组 {
    public static void main(String[] args) {
        // 动态分配方式
        int[] arr = new int[10];
        arr[0] = 1;
        for (int i : arr) {
            System.out.println(i);
        }
        //静态初始化
        double[] duo = {1, 2, 3.4, 6};
        for(int i = 0; i < duo.length;i++){
            System.out.println(duo[i]);
        }
        //动态分配方式，先声明数组，再new分配空间
        double a[];
        a = new double[10];
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }

        //数组反转 方法一
        int temp = 0;
        int[] arr1 = {12, 20, 30, 40, 50, 60};
        for (int i = 0; i < arr1.length / 2; i++) {
            temp = arr1[arr1.length -1 -i];
            arr1[arr1.length -1 -i] = arr1[i];
            arr1[i] = temp;
        }
        for (int i : arr1) {
            System.out.print(i+"\t");
        }
        System.out.println();

        //数组反转 方法二
        int[] arr3 = {11, 22, 33, 44, 55, 66};

        int[] arr4 = new int[arr3.length];
        for(int i = arr3.length-1, j=0; i>=0;i--, j++){
            arr4[j] = arr3[i];
        }
        arr3 = arr4;
        for (int i : arr3) {
            System.out.print(i + "\t");
        }

        //数组扩容
        int[] arr5 = {11, 22, 33};
        int[] arr6 = new int[arr5.length+1];
        for (int i = 0; i < arr5.length; i++) {
            arr6[i] = arr5[i];
        }
        arr6[arr6.length-1] = 44;
        System.out.println();
        arr5 = arr6;
        for (int i = 0; i < arr5.length; i++) {
            System.out.print(arr5[i]+"\t");
        }

        //冒泡排序
        int temp1 = 0;
        int[] arr7 = {13, 4, 56,1, 17, 28};
        for(int i = 0; i < arr7.length - 1; i++){
            for (int y = 0; y < arr7.length -1 - i; y++){
                if(arr7[y] > arr7[y + 1]){
                    temp1 = arr7[y];
                    arr7[y] = arr7[y + 1];
                    arr7[y + 1] = temp1;
                }
            }
            System.out.println("\n==第"+(i+1)+"轮==");
            for (int j = 0; j < arr7.length; j++) {
                System.out.print(arr7[j] + "\t");
            }
        }

        //斐波拉契数

    }
}
